<?php
defined('ANT_ACCESS') or die('Access denided');
/**
 * Ant Framework
 *
 * An open source application development framework for PHP 5
 *
 * @package		Ant Framework
 * @author		Meshin Dmitriy
 * @copyright	Copyright (c) 2008, Meshin Dmitriy
 * @license		GNU Public Lisence v2
 * @link		http://code.google.com/p/ant-framework
 * @desc		Cache and gzip class
 **/
	/*
	 * 	Класс кэширования шаблонов
	 * */
	class ANT_cache{
		protected $configs;
		protected $cache_filename;

		function __construct(){
			$this->configs =& get_config('configs');
		}

		/*
		*	Сжатие трафика
		*/
		public function gzip(){			if (extension_loaded('zlib')){
				if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE){
					ob_start('ob_gzhandler');
				}
			}		}

		/*
		*	Запись кэша
		*/
		public function write_cache(){			$output = ob_get_contents();
			@ob_clean();
			echo $output;
			@file_put_contents($this->cache_filename, $output);
		}

		/*
		*	Проверка и чтение кэша
		*/
		public function check_cache($name){			$this->cache_filename = get_folder('cache').$name.EXT;
			if(file_exists($this->cache_filename)){
				//	вычисляем возраст кэша
				if((date('dYHis') - date("dYHis", filemtime($this->cache_filename))) < $this->configs['template_cachetime']){
					echo file_get_contents($this->cache_filename);
					return TRUE;
				}
				@unlink($this->cache_filename);
			}
			ob_start();
		}
	}
?>